﻿using FirstFloor.ModernUI.Windows.Controls;
using Microsoft.Win32;
using ModernUILogViewer.Business;
using ModernUILogViewer.Content;
using ModernUILogViewer.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace ModernUILogViewer.View
{
    class DialogService : IDialogService
    {
        public string Title { get; set; }
        public string Filter { get; set; }

        public string OpenLogFile()
        {
            string output = null;

            ModernDialog dialog = new ModernDialog
            {
                Title = "Load log file",                
                Content = new ContentLoadLog()
            };

            dialog.ShowDialog();

            dialog.CloseButton.Visibility = Visibility.Collapsed;

            output = ((TailLogViewModel)((UserControl)dialog.Content).DataContext).Filename;

            return output;
        }

        public string[] OpenFile(bool multiselect)
        {
            string[] filenames = null;

            OpenFileDialog dialog = new OpenFileDialog();            
            dialog.Multiselect = multiselect;
            dialog.Filter = this.Filter;
            dialog.Title = this.Title;
            if (dialog.ShowDialog() == true)
            {
                filenames = dialog.FileNames;
            }

            return filenames ?? new string[0];
        }

        public string SaveFile()
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = this.Filter;
            dialog.ShowDialog();

            return dialog.FileName;
        }
    }
}
